"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Basic = exports.AxiosBase = void 0;
const isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch"));
const config_1 = require("../config/config");
const log4js_1 = require("log4js");
const basicUrl = `${config_1.lConfig.adminServer}/public`;
const logger = (0, log4js_1.getLogger)('account-api/api/');
class AxiosBase {
    constructor(token) {
        this.token = token;
    }
    static fetch(url, options = {}) {
        return (0, isomorphic_fetch_1.default)(`${basicUrl}/${url}`, {
            headers: {
                'Content-Type': 'application/json; charset=utf-8',
            },
            ...options
        })
            .catch(error => {
            logger.error(`${basicUrl}/${url}`, error === null || error === void 0 ? void 0 : error.toString());
            return error;
        });
    }
    get(url) {
        return (0, isomorphic_fetch_1.default)(url, {
            headers: {
                'Content-Type': 'application/json; charset=utf-8',
                'Authorization': this.token,
            }
        });
    }
    post(url, body = {}) {
        return (0, isomorphic_fetch_1.default)(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json; charset=utf-8',
                'Authorization': this.token,
            },
            body: JSON.stringify(body)
        });
    }
}
exports.AxiosBase = AxiosBase;
class Basic {
    constructor(token) {
        this.axios = new AxiosBase(token);
    }
    get(url, params) {
        console.log('GET URL: ', `${basicUrl}/${url}`);
        return this.axios.get(`${basicUrl}/${url}`);
    }
    post(url, { body, params } = {}) {
        console.log('POST URL: ', `${basicUrl}/${url}`);
        return this.axios.post(`${basicUrl}/${url}`, body);
    }
}
exports.Basic = Basic;
